package com.qd.common.panda.domain.entity.card;

import com.cdqidi.util.page.BaseQuery;
import com.cdqidi.valid.group.DefaultGroup;
import com.cdqidi.valid.group.DeleteGroup;
import com.cdqidi.valid.group.UpdateGroup;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.qd.common.panda.domain.entity.card.third.ThirdPartyDTO;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Optional;

/**
 * 我的卡卷
 *
 * @author sjk
 */
@EqualsAndHashCode(callSuper = true)
@Getter
@Setter
public class UserCardDTO extends BaseQuery {

    /**
     * 主键
     */
    @NotBlank(message = "卡卷ID不能为空", groups = {DeleteGroup.class, UpdateGroup.class})
    @Size(max = 50, message = "卡卷ID长度不能超过{max}位", groups = {DeleteGroup.class, UpdateGroup.class})
    private String cardId;
    /**
     * 兑换时间
     */
    @NotNull(message = "兑换时间不能为空", groups = DefaultGroup.class)
    private LocalDateTime redemptionTime;
    /**
     * 使用时间
     */
    private LocalDateTime useTime;
    /**
     * 卷有效期
     */
    private LocalDate validityEndTime;
    /**
     * 卡卷状态:1已兑换 2已使用3已过期
     */
    @NotNull(message = "卡卷状态:1已兑换 2已使用3已过期不能为空", groups = DefaultGroup.class)
    private Integer state;
    /**
     * 卷信息
     */
    @NotBlank(message = "卷信息不能为空", groups = DefaultGroup.class)
    @Size(max = 50, message = "卷信息长度不能超过{max}位", groups = DefaultGroup.class)
    private String cardMsgId;
    /**
     * 用户ID
     */
    @NotBlank(message = "用户ID不能为空", groups = DefaultGroup.class)
    @Size(max = 50, message = "用户ID长度不能超过{max}位", groups = DefaultGroup.class)
    private String userId;
    /**
     * 是否系统发放
     */
    @JsonIgnore
    private String systemDistribution;
    /**
     * 订单ID
     */
    private String orderId;
    /**
     * 卷信息
     */
    private CardInfoDTO cardInfoDTO;
    /**
     * 优惠金额
     */
    private BigDecimal preferentialAmount;
    /**
     * 优惠金额显示
     */
    private String preferentialAmountDisplay;
    /**
     * 分享ID
     */
    private String shareId;
    /**
     * 第三方券码
     */
    private String thirdCouponCode;
    /**
     * 事件
     */
    @JsonIgnore
    private String event;
    /**
     * 第三方券商
     */
    @JsonIgnore
    private String thirdParty;
    /**
     * 第三方券商信息
     */
    private ThirdPartyDTO thirdPartyDTO;

    @Override
    public void freeData() {
        this.cardId = null;
        this.redemptionTime = null;
        this.useTime = null;
        this.validityEndTime = null;
        this.state = null;
        this.cardMsgId = null;
        this.userId = null;
        this.orderId = null;
        this.preferentialAmount = null;
        this.preferentialAmountDisplay = null;
        this.shareId = null;
        this.systemDistribution = null;
        Optional.ofNullable(cardInfoDTO).ifPresent(CardInfoDTO::freeData);
        Optional.ofNullable(thirdPartyDTO).ifPresent(ThirdPartyDTO::freeData);
        this.thirdCouponCode = null;
        this.thirdParty = null;
        this.event = null;
        super.freeData();
    }
}
